<?php
namespace  app\index\controller;
use app\index\model\AuthRule;
use Auth\Auth;
use Fuck\Fuck;
use think\Controller;
use think\Db;

/**
 * Created by PhpStorm.
 * User: jieai
 * Date: 2017-08-06
 * Time: 21:56
 */
class AuthController extends Controller{
    public function grouplist()

    {

       $group= Db::name('auth_group')->select();
       $this->assign('groups',$group);
        return $this->fetch();
    }

	public function rulelist()
	{
		$rule=Db::name('auth_rule')->select();
		$this->assign('rule',$rule);
		return $this->fetch();
    }

	public function addrule()
	{
		if ($this->request->isPost()) {
		$authrule=new AuthRule();
		$authrule->name=input('name');
		$authrule->title=input('title');
		$authrule->type=input('type',0);
		$authrule->status=input('status',0);
		$authrule->condition=input('condition');
			if ($authrule->save()) {
			return 	redirect("rulelist");
			}
			return redirect("index/index/index");


		}
		return $this->fetch();
    }

	public function deleterule()
	{
		$authrule=AuthRule::get(input('id'));
		if ($authrule->delete()) {
			$this->success('删除成功!',"rulelist");
		}
    }

	public function addgroup()
	{
		$rule=Db::name('auth_rule')->select();
		$this->assign('rulelist',$rule);
		if ($this->request->isPost()) {
			$data['title']=input('title');
			$data['status']=input('status');
			$rules=input('rules/a');
			$ruleslisst=implode(",",$rules);
			$data['rules']=$ruleslisst;
			if (Db::name('auth_group')->insert($data)) {
				return $this->success('操作成功!');
			}
			return $this->error('shibai');

		}
		return $this->fetch();
    }
	public function adminlist()
	{
		$adminlist=Db::name('admin')->select();
		$this->assign('adminlist',$adminlist);
		return $this->fetch();
    }
};